/*
 * @Author: 邹威鹏(944740645@qq.com)
 * @remarks: 
 */
Page({
  data: {
    goodsData: [],
    userSize: '',
    errImgUrl: 'https://i.loli.net/2019/10/18/DqOUgNf7wjuFpPT.png',
    isGoodsEnsureShow: false,
    isGoodsParamsShow: false,
    isClickPayBtn: false
  },
  onLoad: function (options) {
    const eventChannel = this.getOpenerEventChannel();
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('sendDetailData', (res) => {
      let goodsData = res.data;
      // 处理数据
      goodsData.sliderImage = goodsData.sliderImage.split(',');
      this.setData({
        goodsData
      })
    })
  },
  onReady: function () {
  },
  onShow: function () {
  },
  onHide: function () {
  },
  onUnload: function () {
  },
  onPullDownRefresh: function () {
  },
  onReachBottom: function () {
  },
  onShareAppMessage: function () {
  },
  clickPayBtn() {
    console.log('clickPayBtn');
    this.setData({
      isClickPayBtn: true
    })
  },
  onClose() {
    this.setData({
      isClickPayBtn: false,
      isGoodsEnsureShow: false,
      isGoodsParamsShow: false,
    })
  },
  sizeChange(e) {
    // console.log("当前选择的是", e.detail.value, "码");
    let idx = e.detail.value;
    this.setData({
      userSize: this.data.goodsData.productAttrValues[idx]
    })
  },
  goToPay() {
    if (wx.getStorageSync('token'))// 判断登录
      if (this.data.userSize || this.data.goodsData.productAttrValues.length == 0)// 判断选择码数
      {
        wx.navigateTo({
          url: '../payment/payment',
          success: (res) => {
            // 传递商品数据，用户信息，尺寸
            res.eventChannel.emit('sendDetailData', {
              data: {
                goodsData: this.data.goodsData,
                userSize: this.data.userSize,
              }
            });
          },
        });
      } else {
        wx.showToast({
          title: '请先选择尺码',
          icon: 'none',
          image: '',
          duration: 1500,
          mask: false
        });
      }
    else
      wx.showToast({
        title: '请先登陆',
        duration: 1500,
        mask: false
      });
  },
  goodsEnsureShow() {
    console.log('handleClick');
    this.setData({
      isGoodsEnsureShow: true
    })
  },
  goodsParamsShow() {
    console.log('handleClick');
    this.setData({
      isGoodsParamsShow: true
    })
  }
})
